package com.example.stock.service.impl;

import com.example.stock.service.RankService;
import com.example.stock.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RankServiceImpl implements RankService {

    @Autowired
    RedisService redisService;

    @Override
    public List<String> getStocksByRank() {
        return redisService.zRevRange("STOCK_RANK", 0, -1).stream().map(Object::toString).toList();
    }

    @Override
    public void updateRankByStock(String stock) {
        redisService.add("STOCK_RANK", stock, System.currentTimeMillis());
    }
}